import book.BookList;
import user.AdminUser;
import user.NormalUser;
import user.User;

import java.util.Scanner;

public class Main {

    public static User longin() {
        System.out.println("请输入姓名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        System.out.println("0.管理员  1.普通用户");
        System.out.println("请选择权限：");
        int choice = scanner.nextInt();

        //通过choice 来实例不同的用户
        if (choice == 1) {
            return new NormalUser(name);
        } else if (choice == 0) {
            return new AdminUser(name);
        } else {
            System.out.println("暂未开放该权限");
            return null;
        }
    }

    public static void main(String[] args) {
        //0.初始化数据
        BookList bookList = new BookList();

        //1.login
        User user = longin();//向上转型 为父类User
        while (true) {
            assert user != null;
            int choice = user.menu();//多态 实现对不同的用户有不同的行为

            user.operation(choice, bookList);
        }
    }
}
